package com.xiaoshuidi.cloud.module.iot.controller.app.face;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageParam;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.iot.controller.app.face.vo.AppFaceDatabaseCreateReq;
import com.xiaoshuidi.cloud.module.iot.controller.app.face.vo.AppFaceDatabaseEditReq;
import com.xiaoshuidi.cloud.module.iot.controller.app.face.vo.AppFaceDatabasePageResp;
import com.xiaoshuidi.cloud.module.iot.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.iot.service.FaceDatabaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 租户APP - 智能门禁:人脸库相关接口
 *
 * @Author Feng
 * @date 2023/6/26
 */
@RestController
@Tag(name = "租户APP - 智能门禁")
@RequiredArgsConstructor
@RequestMapping(ApiConstants.NAME + "/face-database")
public class AppFaceDatabaseController {

    private final FaceDatabaseService faceDatabaseService;

    /**
     * app-添加人脸
     *
     * @param req
     * @return
     */
    @Operation(summary = "app-添加人脸")
    @Parameter(name = "req", description = "智能门禁请求对象")
    @PostMapping("/create")
    public CommonResult<Boolean> create(@RequestBody AppFaceDatabaseCreateReq req) {
        return CommonResult.success(faceDatabaseService.appCreate(req));
    }

    /**
     * app-分页列表
     *
     * @param req
     * @return
     */
    @Operation(summary = "app-分页列表")
    @Parameter(name = "req", description = "分页请求对象")
    @GetMapping("/page")
    public CommonResult<PageResult<AppFaceDatabasePageResp>> page(PageParam req) {
        return CommonResult.success(faceDatabaseService.appPage(req));
    }

    /**
     * app-根据ID修改
     *
     * @param req
     * @return
     */
    @Operation(summary = "app-根据ID修改")
    @Parameter(name = "req", description = "智能门禁请求对象")
    @PostMapping("/edit")
//    @PreAuthorize("@ss.hasAnyPermissions('iot:face-database:edit')")
    public CommonResult<Boolean> edit(@RequestBody @Valid AppFaceDatabaseEditReq req) {
        return CommonResult.success(faceDatabaseService.appEdit(req));
    }

    /**
     * app-删除人脸信息
     *
     * @param id
     * @return
     */
    @Operation(summary = "app-删除人脸信息")
    @Parameter(name = "id", description = "人脸信息id")
    @PostMapping("/remove")
//    @PreAuthorize("@ss.hasAnyPermissions('iot:face-database:remove')")
    public CommonResult<Boolean> remove(Long id) {
        return CommonResult.success(faceDatabaseService.remove(id));
    }

    /**
     * app-租客人脸信息
     *
     * @return
     */
    @Operation(summary = "app-租客人脸信息")
    @GetMapping("/renter-info")
    public CommonResult<AppFaceDatabasePageResp> renterInfo() {
        return CommonResult.success(faceDatabaseService.renterInfo());
    }
}
